<!DOCTYPE html>
<html>
	<head>
		<title>create ajax</title>
	</head>
	<body>
		<input type="button" value="AjaxRead" id="button1"/>
	</body>
	<script>
		window.onload=function(){
			var oBtn = document.getElementById("button1");
			oBtn.onclick = function(){
				//1.创建Ajax对象,并处理兼容问题
				if(window.XMLHttpRequest){
					var oAjax = new XMLHttpRequest();
				}else{
					var oAjax=new ActiveXObject("Microsoft.XMLHTTP");
				}
				
				//2.连接服务器
				//open(方法, 文件名, 异步传输)
				oAjax.open('GET', 'arr.txt', true);
				
				//3.发送请求
				oAjax.send();
				
				//4.接收返回
				oAjax.onreadystatechange=function ()
				{
					//oAjax.readyState	//浏览器和服务器，进行到哪一步了
					if(oAjax.readyState==4)	//读取完成
					{
						if(oAjax.status==200)	//成功
						{
							alert('成功：'+oAjax.responseText);
						}
						else
						{
							alert('失败:'+oAjax.status);
						}
					}
				};
			}
		}
	</script>
</html>